<?php
########################################################################################
# Empresa :     Tecnopac Informatica;                                                  #
# Autor:        Deiverson Pacheco;                                                     #
# Data Criação: 18/12/2010;                                                            #
########################################################################################
session_start();
header("Cache-control: private");
include_once("../../includes/session.php");


//Linha para formatação de caracteres com acentuação
header("Content-Type: text/html; charset=ISO-8859-1",true);


//======================================================================================
//==> Include obrigatórias no script
//======================================================================================
include_once('../../includes/classes/class.TemplatePower.php');
include_once('../../includes/classes/class.Conexao.php');
include_once('../../includes/classes/class.Geral.php');

//======================================================================================
//==> Inicializar Classes
//======================================================================================
$not  = new Persist;
$not2 = new Persist;

$data = new getData;
$cor  = new ColorTr;
$util = new Util;
$vld  = new ValidarDados;
$sql  = new SqlInjection;

//======================================================================================
//==> Instanciar TemplatePower para juntar o PHP + HTML
//======================================================================================
$tpl  = new TemplatePower('../../html/estoque/popup_categoria_popup.html');
$tpl->prepare();


//======================================================================================
//==> Recebe variaveis de pesquisa
//======================================================================================
$busca  = @$_GET['busca'];
$id		= @$_GET['id'] == '' ? 0 : $_GET['id'];
$ultimo	= @$_GET['ultimo'] == '' ? 0 : $_GET['ultimo'];

$sql_busca = '';
if($busca != ''){
   $busca = $sql->tratar($busca,50);
   $sql_busca = " AND nome like '%$busca%' ";
}

$cont   = 1;

$not->sql = " SELECT `mostra_caminho_percorrido`($id) AS caminho ";
$not->ler();
$not->ini();

$tpl->assign("caminho",$not->caminho);

$not->sql = "SELECT * FROM produtos_categorias
				WHERE id_pai = $id ";



//PRIMEIRA PARTE EH DESTINADA AO VOLTAR
$tpl->newBlock('LOOP');
$tpl->assign('cont',$cont);
$cont++;
		
$not2->sql = " SELECT id_pai FROM produtos_categorias WHERE id = $ultimo ";
$not2->ler();
$not2->ini();

$tpl->assign('nome',"<a href='popup_categoria_popup.php?ultimo=".$not2->id_pai."&id=". $ultimo ."'> Voltar </a>");
$tpl->assign('cor', $cor->altColor());
$tpl->assign('dsb', " disabled ");		

if($not->ler()>0){
		
	while($not->ini()){
		$tpl->newBlock('LOOP');
		$tpl->assign('cont',$cont);
		$cont++;
		$tpl->assign('id', $not->id);
		$tpl->assign('par_id',$not->id);
		$tpl->assign('desc',$not->nome);
		
		$tpl->assign('nome',"<a href='popup_categoria_popup.php?ultimo=".$not->id_pai."&id=". $not->id ."'>". $not->nome."</a>");
		$tpl->assign('ativo', $not->ativo);
		$tpl->assign('cor', $cor->altColor());


	}
}



$tpl->goToBlock('_ROOT');

//======================================================================================
//==> Enviar página unificada PHP + HTML
//======================================================================================
$tpl->showUnAssigned( false );  // para debug. na hora de publicar, setar para false
$tpl->printToScreen();
?>